package com.qingke.java.test0831;

import java.util.HashSet;
import java.util.Set;

public class User {
	private String userName;
	private String userPassword;
	private double gold;
	private Set<Commodity> myStuff = new HashSet<>();
	
	public User(String userName, String userPassword) {
		this.userName = userName;
		this.userPassword = userPassword;
		//this.gold = 1500;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	public double getGold() {
		return gold;
	}

	public void setGold(double gold) {
		this.gold = gold >= 0 ? gold : 0;
	}
	
	public Set<Commodity> getMyStuff() {
		return myStuff;
	}

	public void setMyStuff(Commodity commodity) {
		this.myStuff.add(commodity);
	}

	@Override
	public int hashCode() {
		return (getClass().getName() + "@" + getUserName()).hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if(this == obj) return true;
		
		if(obj instanceof User) {
			User user = (User)obj;
			return userName.equals(user.userName);
		} 
		
		return false;
	}
	
}
